/* 
 * File:   timer.h
 * Author: hongkang.tao
 *
 * Created on June 10, 2021, 3:44 PM
 */
#ifndef  _timebase_h_
#define  _timebase_h_

#include "protocal.h"


enum 
{
	TIMER_BAT_LOW_VOLTAGE = 0,	
	TIMER_LOAD_RECOVERY,
	TIMER_CHECK_BATTERY_LOST,
#if CHECK_BAT_RES_EN > 0
	TIMER_CHECK_BATTERY_RESISTANCE,
#endif
	TIMER_CHECK_BAT_INFO,
	TIMER_CHECK_AC_VOLTAGE,
	TIMER_CHECK_CHARGER,
	TIMER_CHECK_BAT_FULL,
	TIMER_CHARGER_OPEN_DELAY,
	TIMER_MAIN_OPEN_DELAY,
	USER_TIMER_NUM
};

extern uint16_t gu16_timer[USER_TIMER_NUM];   
    
#define IS_TIMER_END(t_num)         (gu16_timer[(t_num)] == 1 ? 1 : 0)
#define CLEAR_TIMER(t_num)          (gu16_timer[(t_num)] = 0)
#define IS_TIMER_STARTED(t_num)     (gu16_timer[(t_num)] != 0 ? 1 : 0)
#define IS_TIMER_RUNNING(t_num)     (gu16_timer[(t_num)] > 1 ? 1 : 0)
/**
 max timer can be set: 65535 x 10ms /1000ms = 655.53s
 */
#define SET_TIMER_10MS(t_num, n10ms)   (gu16_timer[(t_num)] = (n10ms) + 1)   
#define SET_TIMER_MS(t_num, ms)      (SET_TIMER_10MS((t_num), (ms)/10))

//void Delay_us(uint16_t tick);
//void Delay_ms(uint16_t tick);
void user_timer_work(void);


#endif
